package TCP.Case;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) {
        System.out.println("客户端启动...");

        try {
            Socket socket = new Socket("localhost",7777);//创建Socket通信管道请求服务端("172.0.0.1",7777)连接
            OutputStream inputStream = socket.getOutputStream();//从socket通信管道中获取字节输出流 为服务端发送数据
            PrintStream printStream = new PrintStream(inputStream);//将字节输出流封装为打印流 更高效
            Scanner sc=new Scanner(System.in);
            String msg="";
            while (!"exit".equals(msg)){
                System.out.print("框框:");
                msg = sc.nextLine();
                printStream.println(msg);//要带换行 不然对方接收不到(TCP的严格通信)
                printStream.flush();
            }
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
